let path = require('path');
let HtmlWebpackPlugin = require('html-webpack-plugin');

//tree-shaking

module.exports = {
    mode: 'development',
    optimization: {
        // 分割代码
        splitChunks: {
            // 缓存组
            cacheGroups: {
                // 忽略模块
                vendor: {
                    // 优先级 因为对象是无序的，所以要配这个
                    priority: 1,
                    test: /node_modules/,
                    chunks: 'initial',
                    // 最小0个字节
                    minSize: 0,
                    // 最小两个位置应用
                    minChunks: 2
                },
                common: {
                    chunks: 'initial',
                    // 最小0个字节
                    minSize: 0,
                    // 最小两个位置应用
                    minChunks: 2
                }
            }
        }
    },
    entry: {
        index: './src/index.js',
        main: './src/main.js'
    },
    output: {
        filename: '[name].js',
        path: path.resolve('dist')
    },
    devServer: {
        contentBase: 'dist',
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './public/index.html',
            filename: 'index.html'
        }),
    ]
}